package com.yzd.learnjava.holding;

import java.util.Iterator;


import com.yzd.learnjava.util.Print;
/*
 * Iteratable
 */
public class IteratableClass implements Iterable<String> {
	protected String[] words = ("and that is how we know the Earth to Banana-shaped.").split(" ");
	
	public Iterator<String> iterator(){
		return new Iterator<String>() {
			private int index = 0;
			public boolean hasNext() {
				return index < words.length;
			}
			
			public String next() {
				return words[index++];
			}
			
			public void remove() {
				throw new UnsupportedOperationException();
			}
		};
	}
	
	public static void main(String[] args) {
		for(String s : new IteratableClass()) {
			Print.print(s);
		}
	}
}
